<?php
namespace Home\Controller;
class OrderController extends HomeController {
    public function addOrder(){
        $email = $_SESSION['email'];
        $uid = M('user')->where('email="'.$email.'"')->select();
        $uid = $uid[0]['u_id'];
        $model = M('carts');
        $cart = $model->where("cu_id='".$uid."'")->select();
        foreach($cart as $v){
            $o_detail = M('o_detail');
            $data['o_d_oid'] = I('post.t');
            $data['o_d_gid'] = $v['cg_id'];
            $data['o_d_num'] = $v['cg_num'];
            $o_detail->add($data);
        }
        $orders = M('orders');
        $list['o_uid'] = $uid;
        $list['o_rand_id'] = I('post.t');
        $list['addtime'] = time();
        $orders->add($list);

        $coin = I('post.coin');
        $score = $coin/100;
        $user = M('user_info');
        $user->where('ui_id ="'.$uid.'"')->setDec('dotacoin',$coin);
        $user->where('ui_id ="'.$uid.'"')->setInc('score',$score);

        M('carts')->where('cu_id="'.$uid.'"')->delete();
    }

    public function del(){
        $id = $_POST['id'];
        $data['o_d_del'] = 1;
        M('o_detail')->where('o_d_id ="'.$id.'"')->save($data);
    }
}